package br.uninove.jimage.view;

import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class PathClasseView extends JPanel {

	private static final long serialVersionUID = 1L;
	private JLabel lblClasse = null;
	private JTextField txtPathClasse = null;
	private JButton btnAbrir = null;
	
	
	/**
	 * This is the default constructor
	 */
	public PathClasseView() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		
		lblClasse = new JLabel();
		lblClasse.setText("Classe:");
		this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		this.setSize(589, 52);
		this.setBorder(BorderFactory.createEmptyBorder(12, 5, 12, 5));
		this.add(lblClasse, null);
		this.add(getTxtPathClasse(), null);
		this.add(getBtnAbrir(), null);
	}

	/**
	 * This method initializes txtPathClasse	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	public JTextField getTxtPathClasse() {
		if (txtPathClasse == null) {
			txtPathClasse = new JTextField();
		}
		return txtPathClasse;
	}

	/**
	 * This method initializes btnAbrir	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnAbrir() {
		if (btnAbrir == null) {
			btnAbrir = new JButton();
			btnAbrir.setText("Abrir");
			btnAbrir.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println();
					
					
					JFileChooser chooser = DemoJFileChooser.getChooser();
					
					if ( chooser.showOpenDialog(((JButton)e.getSource()).getParent()) == JFileChooser.APPROVE_OPTION) {
						txtPathClasse.setText(chooser.getSelectedFile().toString());
					} else {
						System.out.println("No Selection ");
					}
				}

			});
		}
		
		return btnAbrir;
	}

	
	
	
	public static class DemoJFileChooser extends JPanel {
		/**
		 * 
		 */
		private static final long serialVersionUID = -4899819248611001045L;
		private static JFileChooser chooser;

		
		public Dimension getPreferredSize() {
			return new Dimension(200, 200);
		}

		public static JFileChooser getChooser() {
			if (chooser == null) {
				chooser = new JFileChooser();
				chooser.setCurrentDirectory(new java.io.File("."));
				chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
				chooser.setAcceptAllFileFilterUsed(false);
			}
			return chooser;
		}
	}
}  //  @jve:decl-index=0:visual-constraint="8,7"
